package com.gethb.prod.controller;

import javax.annotation.Resource;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gethb.prod.vo.*;
//import com.gethb.pub.utils.BaseInVo;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
//import com.gethb.prod.service.IAgainMessageService;
//import com.gethb.prod.service.ISendMessageService;
//import com.gethb.prod.service.IUserInfAddService;
import com.gethb.prod.service.IUserLoginService;

@Controller
@RequestMapping("/user")
public class UserInfAddApplication {

//    private static final Logger LOG = LoggerFactory.getLogger(UserInfAddApplication.class);                     `

//    // 用户注册发送短信实现类
//    @Resource(name = "sendMessageService")
//    private ISendMessageService iSendMessageService;
//
//    // 重新发送短信实现类
//    @Resource(name = "againMessageService")
//    private IAgainMessageService iAgainMessageService;

    // 用户登陆实现类
    @Resource(name = "userLoginService")
    private IUserLoginService iUserLoginService;

    /**
     * 用户登陆
     */
    @ResponseBody
    @PostMapping(value = "/login", produces = "application/json;charset=UTF-8")
    public Result<String> userLogin(@RequestBody JSONObject jsonParam) {
        LoginInVo inVo;
        String token;
        try {
            inVo = JSON.toJavaObject(jsonParam, LoginInVo.class);
            token = iUserLoginService.userLogin(inVo);
        } catch (Exception error) {
            return Result.exception(error.getMessage());
        }
        //
        if (token == null) {
            return Result.badParam("手机号或密码错误");
        } else {
            return Result.success(token);
        }
    }


//    /**
//     * 发送短信验证码
//     */
//    @ResponseBody
//    @PostMapping(value = "/message", produces = "application/json;charset=UTF-8")
//    public String sendMessage(@RequestBody JSONObject jsonParam) {
//        return iSendMessageService.sendMessage(jsonParam.toJSONString());
//    }
//
//    /**
//     * 重发短信验证码
//     */
//    @ResponseBody
//    @PostMapping(value = "/againMessage", produces = "application/json;charset=UTF-8")
//    public String againSendMessage(@RequestBody JSONObject jsonParam) {
//        return iAgainMessageService.sendAgainMessage(jsonParam.toJSONString());
//    }
}
